package com.ruoyi.config.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.config.domain.WebConfig;
import com.ruoyi.config.service.IWebConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统功能Controller
 * 
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/config/config")
public class WebConfigController extends BaseController
{
    @Autowired
    private IWebConfigService webConfigService;

    /**
     * 查询系统功能列表
     */
    @PreAuthorize("@ss.hasPermi('config:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebConfig webConfig)
    {
        startPage();
        List<WebConfig> list = webConfigService.selectWebConfigList(webConfig);
        return getDataTable(list);
    }

    /**
     * 导出系统功能列表
     */
    @PreAuthorize("@ss.hasPermi('config:config:export')")
    @Log(title = "系统功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebConfig webConfig)
    {
        List<WebConfig> list = webConfigService.selectWebConfigList(webConfig);
        ExcelUtil<WebConfig> util = new ExcelUtil<WebConfig>(WebConfig.class);
        util.exportExcel(response, list, "系统功能数据");
    }

    /**
     * 获取系统功能详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:config:query')")
    @GetMapping(value = "/{uid}")
    public AjaxResult getInfo(@PathVariable("uid") Long uid)
    {
        return success(webConfigService.selectWebConfigByUid(uid));
    }

    /**
     * 新增系统功能
     */
    @PreAuthorize("@ss.hasPermi('config:config:add')")
    @Log(title = "系统功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebConfig webConfig)
    {
        return toAjax(webConfigService.insertWebConfig(webConfig));
    }

    /**
     * 修改系统功能
     */
    @PreAuthorize("@ss.hasPermi('config:config:edit')")
    @Log(title = "系统功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebConfig webConfig)
    {
        return toAjax(webConfigService.updateWebConfig(webConfig));
    }

    /**
     * 删除系统功能
     */
    @PreAuthorize("@ss.hasPermi('config:config:remove')")
    @Log(title = "系统功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uids}")
    public AjaxResult remove(@PathVariable Long[] uids)
    {
        return toAjax(webConfigService.deleteWebConfigByUids(uids));
    }
}
